home *** CD-ROM | disk | FTP | other *** search
/ Champak 103 / Vol 103.iso / games / save_pri.swf / scripts / frame_45 / DoAction.as
Encoding:
Text File  |  2010-03-13  |  28.1 KB  |  842 lines

  1. function playSound($soundObj)
  2. {
  3.    var _loc1_ = $soundObj;
  4.    if(_loc1_.position == 0 || _loc1_.position == _loc1_.duration)
  5.    {
  6.       _loc1_.start();
  7.    }
  8. }
  9. function playPelletSound()
  10. {
  11.    pelletSound2.start();
  12. }
  13. function TileClass($walkable, $frame, $style)
  14. {
  15.    var _loc1_ = this;
  16.    _loc1_.walkable = $walkable;
  17.    _loc1_.frame = $frame;
  18.    _loc1_.style = $style;
  19. }
  20. function DoorClass($newCharX, $newCharY)
  21. {
  22.    var _loc1_ = this;
  23.    _loc1_.newCharX = $newCharX;
  24.    _loc1_.newCharY = $newCharY;
  25.    _loc1_.newMap = 1;
  26.    _loc1_.frame = 20;
  27.    _loc1_.walkable = true;
  28.    _loc1_.style = "door";
  29. }
  30. function getMyCorners($x, $y, $ob)
  31. {
  32.    var _loc1_ = $ob;
  33.    _loc1_.downY = Math.floor(($y + _loc1_.height) / game.tileH);
  34.    _loc1_.upY = Math.floor(($y - _loc1_.height) / game.tileH);
  35.    _loc1_.leftX = Math.floor(($x - _loc1_.width) / game.tileW);
  36.    _loc1_.rightX = Math.floor(($x + _loc1_.width) / game.tileW);
  37.    _loc1_.upLeft = game["tile" + _loc1_.upY + "_" + _loc1_.leftX].walkable;
  38.    _loc1_.upRight = game["tile" + _loc1_.upY + "_" + _loc1_.rightX].walkable;
  39.    _loc1_.downLeft = game["tile" + _loc1_.downY + "_" + _loc1_.leftX].walkable;
  40.    _loc1_.downRight = game["tile" + _loc1_.downY + "_" + _loc1_.rightX].walkable;
  41.    ┬º┬ºpush(_loc1_);
  42.    if(_loc1_ == _root.hero)
  43.    {
  44.       if(!_loc1_.upLeft)
  45.       {
  46.          _loc1_.upLeft = game["tile" + _loc1_.upY + "_" + _loc1_.leftX].style == "openGoalDoor";
  47.       }
  48.       if(!_loc1_.upRight)
  49.       {
  50.          _loc1_.upRight = game["tile" + _loc1_.upY + "_" + _loc1_.rightX].style == "openGoalDoor";
  51.       }
  52.       if(!_loc1_.downLeft)
  53.       {
  54.          _loc1_.downLeft = game["tile" + _loc1_.downY + "_" + _loc1_.leftX].style == "openGoalDoor";
  55.       }
  56.       if(!_loc1_.downRight)
  57.       {
  58.          _loc1_.downRight = game["tile" + _loc1_.downY + "_" + _loc1_.rightX].style == "openGoalDoor";
  59.       }
  60.    }
  61.    var _loc0_ = _loc1_.upLeft && _loc1_.downLeft && _loc1_.upRight && _loc1_.downRight;
  62.    _loc1_ = ┬º┬ºpop();
  63.    return _loc0_;
  64. }
  65. function moveChar($ob, $dirX, $dirY)
  66. {
  67.    var _loc1_ = $ob;
  68.    var _loc3_ = _root;
  69.    if(getMyCorners(_loc1_.x + _loc1_.speed * $dirX,_loc1_.y + _loc1_.speed * $dirY,_loc1_))
  70.    {
  71.       _loc1_.y += _loc1_.speed * $dirY;
  72.       _loc1_.x += _loc1_.speed * $dirX;
  73.       _loc1_.clip._x = _loc1_.x;
  74.       _loc1_.clip._y = _loc1_.y;
  75.       _loc1_.xTile = Math.floor(_loc1_.clip._x / game.tileW);
  76.       _loc1_.ytile = Math.floor(_loc1_.clip._y / game.tileH);
  77.       _loc1_.clip.gotoAndStop(_loc1_.curDir);
  78.       if(_loc1_ == _loc3_.hero)
  79.       {
  80.          if(game.totalPellets > 0)
  81.          {
  82.             var _loc2_ = "tile" + _loc1_.yTile + "_" + _loc1_.xTile;
  83.             switch(game[_loc2_].style)
  84.             {
  85.                case "pellet":
  86.                   game[_loc2_] = _loc3_.Tile1;
  87.                   game.clip[_loc2_].gotoAndStop(game[_loc2_].frame);
  88.                   game.totalPellets--;
  89.                   score += 10;
  90.                   playPelletSound();
  91.                   break;
  92.                case "powerPellet":
  93.                   game[_loc2_] = _loc3_.Tile1;
  94.                   game.clip[_loc2_].gotoAndStop(game[_loc2_].frame);
  95.                   game.totalPellets--;
  96.                   score += 20;
  97.                   powerUp();
  98.                   playSound(ppSound);
  99.                   break;
  100.                case "keyLeft":
  101.                   playSound(keySound);
  102.                   game[_loc2_] = _loc3_.Tile1;
  103.                   game.clip[_loc2_].gotoAndStop(game[_loc2_].frame);
  104.                   game["tile" + _loc1_.yTile + "_" + (_loc1_.xTile + 1)] = _loc3_.Tile1;
  105.                   game.clip["tile" + _loc1_.yTile + "_" + (_loc1_.xTile + 1)].gotoAndStop(game[_loc2_].frame);
  106.                   game["tile" + _loc1_.yTile + "_" + (_loc1_.xTile + 2)] = _loc3_.Tile1;
  107.                   game.clip["tile" + _loc1_.yTile + "_" + (_loc1_.xTile + 2)].gotoAndStop(game[_loc2_].frame);
  108.                   game.totalPellets -= 3;
  109.                   score += 30;
  110.                   break;
  111.                case "keyMiddle":
  112.                   playSound(keySound);
  113.                   game[_loc2_] = _loc3_.Tile1;
  114.                   game.clip[_loc2_].gotoAndStop(game[_loc2_].frame);
  115.                   game["tile" + _loc1_.yTile + "_" + (_loc1_.xTile - 1)] = _loc3_.Tile1;
  116.                   game.clip["tile" + _loc1_.yTile + "_" + (_loc1_.xTile - 1)].gotoAndStop(game[_loc2_].frame);
  117.                   game["tile" + _loc1_.yTile + "_" + (_loc1_.xTile + 1)] = _loc3_.Tile1;
  118.                   game.clip["tile" + _loc1_.yTile + "_" + (_loc1_.xTile + 1)].gotoAndStop(game[_loc2_].frame);
  119.                   game.totalPellets -= 3;
  120.                   score += 30;
  121.                   break;
  122.                case "keyRight":
  123.                   playSound(keySound);
  124.                   game[_loc2_] = _loc3_.Tile1;
  125.                   game.clip[_loc2_].gotoAndStop(game[_loc2_].frame);
  126.                   game["tile" + _loc1_.yTile + "_" + (_loc1_.xTile - 2)] = _loc3_.Tile1;
  127.                   game.clip["tile" + _loc1_.yTile + "_" + (_loc1_.xTile - 2)].gotoAndStop(game[_loc2_].frame);
  128.                   game["tile" + _loc1_.yTile + "_" + (_loc1_.xTile - 1)] = _loc3_.Tile1;
  129.                   game.clip["tile" + _loc1_.yTile + "_" + (_loc1_.xTile - 1)].gotoAndStop(game[_loc2_].frame);
  130.                   game.totalPellets -= 3;
  131.                   score += 30;
  132.             }
  133.             if(game.totalPellets == 0)
  134.             {
  135.                game[game.goalDoor] = _loc3_.Tile11;
  136.                game.clip[game.goalDoor].gotoAndStop(game[game.goalDoor].frame);
  137.                game.clip.cage.gotoAndPlay("open");
  138.             }
  139.          }
  140.          else if(game["tile" + _loc1_.yTile + "_" + _loc1_.xTile].style == "goal")
  141.          {
  142.             game.interaction = false;
  143.             levelUp.gotoAndPlay("reveal");
  144.          }
  145.       }
  146.       if(game["tile" + _loc1_.yTile + "_" + _loc1_.xTile].style == "door")
  147.       {
  148.          changeMap(_loc1_);
  149.       }
  150.       return true;
  151.    }
  152.    if(_loc1_ == _loc3_.hero)
  153.    {
  154.       heroChangeDirections();
  155.       return false;
  156.    }
  157.    _loc1_.x = (_loc1_.xTile + 0.5) * game.tileW;
  158.    _loc1_.y = (_loc1_.yTile + 0.5) * game.tileH;
  159.    _loc1_.clip._x = _loc1_.x;
  160.    _loc1_.clip._y = _loc1_.y;
  161. }
  162. function EnemyClass($dir)
  163. {
  164.    var _loc1_ = this;
  165.    _loc1_.dir = 2;
  166.    _loc1_.speeds = {normal:5.25,afraid:3,eaten:0,grace:5.25};
  167.    _loc1_.speed = _loc1_.speeds.normal;
  168.    _loc1_.iq = base10;
  169.    _loc1_.state = "normal";
  170.    _loc1_.grace = 0;
  171. }
  172. function enemyBrain()
  173. {
  174.    var i = 0;
  175.    while(i < game.currentEnemies)
  176.    {
  177.       var enemyName = "enemy" + i;
  178.       var _loc1_ = game[enemyName];
  179.       if(_loc1_.state == "eaten")
  180.       {
  181.          if(--_loc1_.reviveCount <= 0)
  182.          {
  183.             _loc1_.xTile = 11;
  184.             _loc1_.yTile = 1;
  185.             _loc1_.x = (_loc1_.xTile + 0.5) * game.tileW;
  186.             _loc1_.y = (_loc1_.yTile + 0.5) * game.tileH;
  187.             _loc1_.clip._x = _loc1_.x;
  188.             _loc1_.clip._y = _loc1_.y;
  189.             _loc1_.dir = 3;
  190.             _loc1_.state = "grace";
  191.             _loc1_.clip.gotoAndPlay("grace");
  192.             _loc1_.grace = 20;
  193.          }
  194.       }
  195.       else
  196.       {
  197.          _loc1_.speed = _loc1_.speeds[_loc1_.state];
  198.          if(_loc1_.x == (_loc1_.xTile + 0.5) * game.tileW && _loc1_.y == (_loc1_.yTile + 0.5) * game.tileH)
  199.          {
  200.             var motionChoice = "roam";
  201.             switch(_loc1_.state)
  202.             {
  203.                case "grace":
  204.                   _loc1_.grace = _loc1_.grace - 1;
  205.                   if(_loc1_.grace <= 0)
  206.                   {
  207.                      _loc1_.state = "normal";
  208.                      _loc1_.clip.gotoAndPlay("normal");
  209.                   }
  210.                   break;
  211.                case "afraid":
  212.                   var motionChoice = "flee";
  213.                   break;
  214.                default:
  215.                   if(Math.abs(_loc1_.xTile - hero.xTile) <= 6 && Math.abs(_loc1_.yTile - hero.yTile) <= 6)
  216.                   {
  217.                      if(Math.random() * 100 < Math.min(90,30 + 5 * game.level))
  218.                      {
  219.                         motionChoice = "hunt";
  220.                      }
  221.                      break;
  222.                   }
  223.                   if(_loc1_.xTile == hero.xTile || _loc1_.yTile == hero.yTile)
  224.                   {
  225.                      if(Math.random() * 100 < Math.min(90,30 + 5 * game.level))
  226.                      {
  227.                         motionChoice = "hunt";
  228.                      }
  229.                   }
  230.                   break;
  231.             }
  232.             var reverseDir = 0;
  233.             switch(_loc1_.dir)
  234.             {
  235.                case 1:
  236.                   reverseDir = 3;
  237.                   break;
  238.                case 2:
  239.                   reverseDir = 4;
  240.                   break;
  241.                case 3:
  242.                   reverseDir = 1;
  243.                   break;
  244.                case 4:
  245.                   reverseDir = 2;
  246.             }
  247.             switch(motionChoice)
  248.             {
  249.                case "flee":
  250.                   var dirChoices = [];
  251.                   dirChoices.push(null);
  252.                   dirChoices.push(game["tile" + (_loc1_.yTile - 1) + "_" + _loc1_.xTile].walkable && _loc1_.dir != 3);
  253.                   dirChoices.push(game["tile" + _loc1_.yTile + "_" + (_loc1_.xTile + 1)].walkable && _loc1_.dir != 4);
  254.                   dirChoices.push(game["tile" + (_loc1_.yTile + 1) + "_" + _loc1_.xTile].walkable && _loc1_.dir != 1);
  255.                   dirChoices.push(game["tile" + _loc1_.yTile + "_" + (_loc1_.xTile - 1)].walkable && _loc1_.dir != 2);
  256.                   var _loc2_ = new Array();
  257.                   var _loc3_ = random(2) != 0 ? -1 : 1;
  258.                   if(Math.abs(hero.xTile - _loc1_.xTile) >= Math.abs(hero.yTile - _loc1_.yTile))
  259.                   {
  260.                      if(hero.xTile < _loc1_.xTile)
  261.                      {
  262.                         if(dirChoices[2])
  263.                         {
  264.                            _loc2_.push(2);
  265.                         }
  266.                         if(dirChoices[2 - _loc3_])
  267.                         {
  268.                            _loc2_.push(2 - _loc3_);
  269.                         }
  270.                         if(dirChoices[2 + _loc3_])
  271.                         {
  272.                            _loc2_.push(2 + _loc3_);
  273.                         }
  274.                         if(dirChoices[4])
  275.                         {
  276.                            _loc2_.push(4);
  277.                         }
  278.                      }
  279.                      else
  280.                      {
  281.                         if(dirChoices[4])
  282.                         {
  283.                            _loc2_.push(4);
  284.                         }
  285.                         if(dirChoices[2 - _loc3_])
  286.                         {
  287.                            _loc2_.push(2 - _loc3_);
  288.                         }
  289.                         if(dirChoices[2 + _loc3_])
  290.                         {
  291.                            _loc2_.push(2 + _loc3_);
  292.                         }
  293.                         if(dirChoices[2])
  294.                         {
  295.                            _loc2_.push(2);
  296.                         }
  297.                      }
  298.                   }
  299.                   else if(hero.yTile < _loc1_.yTile)
  300.                   {
  301.                      if(dirChoices[3])
  302.                      {
  303.                         _loc2_.push(3);
  304.                      }
  305.                      if(dirChoices[3 - _loc3_])
  306.                      {
  307.                         _loc2_.push(3 - _loc3_);
  308.                      }
  309.                      if(dirChoices[3 + _loc3_])
  310.                      {
  311.                         _loc2_.push(3 + _loc3_);
  312.                      }
  313.                      if(dirChoices[1])
  314.                      {
  315.                         _loc2_.push(1);
  316.                      }
  317.                   }
  318.                   else
  319.                   {
  320.                      if(dirChoices[1])
  321.                      {
  322.                         _loc2_.push(1);
  323.                      }
  324.                      if(dirChoices[3 - _loc3_])
  325.                      {
  326.                         _loc2_.push(3 - _loc3_);
  327.                      }
  328.                      if(dirChoices[3 + _loc3_])
  329.                      {
  330.                         _loc2_.push(3 + _loc3_);
  331.                      }
  332.                      if(dirChoices[3])
  333.                      {
  334.                         _loc2_.push(3);
  335.                      }
  336.                   }
  337.                   var dirX = 0;
  338.                   var dirY = 0;
  339.                   _loc1_.dir = _loc2_[0];
  340.                   break;
  341.                case "hunt":
  342.                   var dirChoices = [];
  343.                   dirChoices.push(null);
  344.                   dirChoices.push(game["tile" + (_loc1_.yTile - 1) + "_" + _loc1_.xTile].walkable && _loc1_.dir != 3);
  345.                   dirChoices.push(game["tile" + _loc1_.yTile + "_" + (_loc1_.xTile + 1)].walkable && _loc1_.dir != 4);
  346.                   dirChoices.push(game["tile" + (_loc1_.yTile + 1) + "_" + _loc1_.xTile].walkable && _loc1_.dir != 1);
  347.                   dirChoices.push(game["tile" + _loc1_.yTile + "_" + (_loc1_.xTile - 1)].walkable && _loc1_.dir != 2);
  348.                   _loc2_ = new Array();
  349.                   _loc3_ = random(2) != 0 ? -1 : 1;
  350.                   if(Math.abs(hero.xTile - _loc1_.xTile) >= Math.abs(hero.yTile - _loc1_.yTile))
  351.                   {
  352.                      if(hero.xTile < _loc1_.xTile)
  353.                      {
  354.                         if(dirChoices[4])
  355.                         {
  356.                            _loc2_.push(4);
  357.                         }
  358.                         if(dirChoices[2 - _loc3_])
  359.                         {
  360.                            _loc2_.push(2 - _loc3_);
  361.                         }
  362.                         if(dirChoices[2 + _loc3_])
  363.                         {
  364.                            _loc2_.push(2 + _loc3_);
  365.                         }
  366.                         if(dirChoices[2])
  367.                         {
  368.                            _loc2_.push(2);
  369.                         }
  370.                      }
  371.                      else
  372.                      {
  373.                         if(dirChoices[2])
  374.                         {
  375.                            _loc2_.push(2);
  376.                         }
  377.                         if(dirChoices[2 - _loc3_])
  378.                         {
  379.                            _loc2_.push(2 - _loc3_);
  380.                         }
  381.                         if(dirChoices[2 + _loc3_])
  382.                         {
  383.                            _loc2_.push(2 + _loc3_);
  384.                         }
  385.                         if(dirChoices[4])
  386.                         {
  387.                            _loc2_.push(4);
  388.                         }
  389.                      }
  390.                   }
  391.                   else if(hero.yTile < _loc1_.yTile)
  392.                   {
  393.                      if(dirChoices[1])
  394.                      {
  395.                         _loc2_.push(1);
  396.                      }
  397.                      if(dirChoices[3 - _loc3_])
  398.                      {
  399.                         _loc2_.push(3 - _loc3_);
  400.                      }
  401.                      if(dirChoices[3 + _loc3_])
  402.                      {
  403.                         _loc2_.push(3 + _loc3_);
  404.                      }
  405.                      if(dirChoices[3])
  406.                      {
  407.                         _loc2_.push(3);
  408.                      }
  409.                   }
  410.                   else
  411.                   {
  412.                      if(dirChoices[3])
  413.                      {
  414.                         _loc2_.push(3);
  415.                      }
  416.                      if(dirChoices[3 - _loc3_])
  417.                      {
  418.                         _loc2_.push(3 - _loc3_);
  419.                      }
  420.                      if(dirChoices[3 + _loc3_])
  421.                      {
  422.                         _loc2_.push(3 + _loc3_);
  423.                      }
  424.                      if(dirChoices[1])
  425.                      {
  426.                         _loc2_.push(1);
  427.                      }
  428.                   }
  429.                   var dirX = 0;
  430.                   var dirY = 0;
  431.                   _loc1_.dir = _loc2_[0];
  432.                   break;
  433.                case "roam":
  434.                   var dirChoices = [];
  435.                   if(game["tile" + (_loc1_.yTile - 1) + "_" + _loc1_.xTile].walkable && _loc1_.dir != 3)
  436.                   {
  437.                      dirChoices.push(1);
  438.                   }
  439.                   if(game["tile" + _loc1_.yTile + "_" + (_loc1_.xTile + 1)].walkable && _loc1_.dir != 4)
  440.                   {
  441.                      dirChoices.push(2);
  442.                   }
  443.                   if(game["tile" + (_loc1_.yTile + 1) + "_" + _loc1_.xTile].walkable && _loc1_.dir != 1)
  444.                   {
  445.                      dirChoices.push(3);
  446.                   }
  447.                   if(game["tile" + _loc1_.yTile + "_" + (_loc1_.xTile - 1)].walkable && _loc1_.dir != 2)
  448.                   {
  449.                      dirChoices.push(4);
  450.                   }
  451.                   if(!(Math.abs(dirChoices[0] - reverseDir) == 2 && dirChoices.length == 1))
  452.                   {
  453.                      _loc1_.dir = dirChoices[Math.floor(Math.random() * dirChoices.length)];
  454.                   }
  455.             }
  456.          }
  457.          _loc1_.clip.dir = _loc1_.dir;
  458.          var dirX = 0;
  459.          var dirY = 0;
  460.          switch(_loc1_.dir)
  461.          {
  462.             case 1:
  463.                dirX = 0;
  464.                dirY = -1;
  465.                break;
  466.             case 2:
  467.                dirX = 1;
  468.                dirY = 0;
  469.                break;
  470.             case 3:
  471.                dirX = 0;
  472.                dirY = 1;
  473.                break;
  474.             case 4:
  475.                dirX = -1;
  476.                dirY = 0;
  477.          }
  478.          moveChar(_loc1_,dirX,dirY);
  479.          var xDist = _loc1_.x - hero.x;
  480.          var yDist = _loc1_.y - hero.y;
  481.          if(Math.sqrt(xDist * xDist + yDist * yDist) < _loc1_.width + hero.width + 5)
  482.          {
  483.             if(_loc1_.state == "normal")
  484.             {
  485.                playSound(deathSound);
  486.                game.interaction = false;
  487.                hero.clip.gotoAndPlay("die");
  488.                livesDisplay.removeOne();
  489.             }
  490.             else if(_loc1_.state == "afraid")
  491.             {
  492.                playSound(deadEnemySound);
  493.                _loc1_.state = "eaten";
  494.                game.eatenEnemies = game.eatenEnemies + 1;
  495.                var eatenPoints = 10 * game.eatenEnemies;
  496.                score += eatenPoints;
  497.                _loc1_.clip.pointValue = eatenPoints;
  498.                _loc1_.clip.gotoAndPlay("eaten");
  499.                _loc1_.reviveCount = 100;
  500.             }
  501.          }
  502.       }
  503.       i++;
  504.    }
  505. }
  506. function moveHero()
  507. {
  508.    var _loc1_ = _root.hero;
  509.    var _loc3_ = 0;
  510.    var _loc2_ = 0;
  511.    if(_loc1_.nextDir != 0)
  512.    {
  513.       var nextDirX = 0;
  514.       var nextDirY = 0;
  515.       switch(_loc1_.nextDir)
  516.       {
  517.          case 5:
  518.             nextDirX = 0;
  519.             nextDirY = 0;
  520.             break;
  521.          case 1:
  522.             nextDirX = 0;
  523.             nextDirY = -1;
  524.             break;
  525.          case 2:
  526.             nextDirX = 1;
  527.             nextDirY = 0;
  528.             break;
  529.          case 3:
  530.             nextDirX = 0;
  531.             nextDirY = 1;
  532.             break;
  533.          case 4:
  534.             nextDirX = -1;
  535.             nextDirY = 0;
  536.       }
  537.       if(getMyCorners(_loc1_.x + _loc1_.speed * nextDirX,_loc1_.y + _loc1_.speed * nextDirY,_loc1_))
  538.       {
  539.          _loc1_.curDir = _loc1_.nextDir;
  540.          _loc1_.nextDir = 0;
  541.          _loc3_ = nextDirX;
  542.          _loc2_ = nextDirY;
  543.       }
  544.    }
  545.    if(_loc3_ == 0 && _loc2_ == 0)
  546.    {
  547.       switch(_loc1_.curDir)
  548.       {
  549.          case 1:
  550.             _loc3_ = 0;
  551.             _loc2_ = -1;
  552.             break;
  553.          case 2:
  554.             _loc3_ = 1;
  555.             _loc2_ = 0;
  556.             break;
  557.          case 3:
  558.             _loc3_ = 0;
  559.             _loc2_ = 1;
  560.             break;
  561.          case 4:
  562.             _loc3_ = -1;
  563.             _loc2_ = 0;
  564.       }
  565.    }
  566.    moveChar(_loc1_,_loc3_,_loc2_);
  567. }
  568. function heroChangeDirections()
  569. {
  570.    hero.curDir = hero.nextDir;
  571.    hero.nextDir = 0;
  572. }
  573. function buildMap($map, $buildMap)
  574. {
  575.    game.clip = _root.tiles;
  576.    if($buildMap)
  577.    {
  578.       level = game.level;
  579.       var mapWidth = $map[0].length;
  580.       var mapHeight = $map.length;
  581.       var i = 0;
  582.       while(i < mapHeight)
  583.       {
  584.          var _loc3_ = 0;
  585.          while(_loc3_ < mapWidth)
  586.          {
  587.             var _loc1_ = "tile" + i + "_" + _loc3_;
  588.             game[_loc1_] = _root["Tile" + $map[i][_loc3_]];
  589.             switch(game[_loc1_].style)
  590.             {
  591.                case "pellet":
  592.                case "powerPellet":
  593.                case "keyLeft":
  594.                case "keyMiddle":
  595.                case "keyRight":
  596.                   game.totalPellets = game.totalPellets + 1;
  597.                   break;
  598.                case "goalDoor":
  599.                   game.goalDoor = _loc1_;
  600.                   break;
  601.             }
  602.             game.clip.attachMovie("tile",_loc1_,i * 100 + _loc3_ * 2);
  603.             game.clip[_loc1_]._x = _loc3_ * game.tileW;
  604.             game.clip[_loc1_]._y = i * game.tileH;
  605.             game.clip[_loc1_].gotoAndStop(game[_loc1_].frame);
  606.             _loc3_ = _loc3_ + 1;
  607.          }
  608.          i++;
  609.       }
  610.    }
  611.    var enemies = enemyList[game.currentMap];
  612.    game.currentEnemies = enemies.length;
  613.    var i = 0;
  614.    while(i < game.currentEnemies)
  615.    {
  616.       var _loc2_ = "enemy" + i;
  617.       game[_loc2_] = _root["Enemy" + enemies[i][0]];
  618.       game.clip.attachMovie("enemy" + enemies[i][0],_loc2_,10001 + i);
  619.       game[_loc2_].state = "normal";
  620.       game[_loc2_].clip = game.clip[_loc2_];
  621.       game[_loc2_].xTile = enemies[i][1];
  622.       game[_loc2_].yTile = enemies[i][2];
  623.       game[_loc2_].width = 6.9;
  624.       game[_loc2_].height = 6.9;
  625.       game[_loc2_].x = game[_loc2_].xTile * game.tileW + game.tileW / 2;
  626.       game[_loc2_].y = game[_loc2_].yTile * game.tileH + game.tileH / 2;
  627.       game[_loc2_].clip._x = game[_loc2_].x;
  628.       game[_loc2_].clip._y = game[_loc2_].y;
  629.       i++;
  630.    }
  631.    game.clip.attachMovie("hero","hero",10000);
  632.    hero.clip = game.clip.hero;
  633.    hero.clip.gotoAndStop(2);
  634.    hero.curDir = 0;
  635.    hero.nextDir = 0;
  636.    hero.xTile = 11;
  637.    hero.yTile = 15;
  638.    hero.x = hero.xTile * game.tileW + game.tileW / 2;
  639.    hero.y = hero.yTile * game.tileH + game.tileH / 2;
  640.    hero.width = 6.9;
  641.    hero.height = 6.9;
  642.    hero.clip._x = hero.x;
  643.    hero.clip._y = hero.y;
  644.    game.powerUp = 0;
  645. }
  646. function changeMap($ob)
  647. {
  648.    var _loc1_ = $ob;
  649.    var _loc2_ = "tile" + _loc1_.yTile + "_" + _loc1_.xTile;
  650.    _loc1_.yTile = game[_loc2_].newCharY;
  651.    _loc1_.xTile = game[_loc2_].newCharX;
  652.    _loc1_.x = _loc1_.xTile * game.tileW + game.tileW / 2;
  653.    _loc1_.y = _loc1_.yTile * game.tileH + game.tileH / 2;
  654. }
  655. function powerUp()
  656. {
  657.    if(game.powerUp == 0)
  658.    {
  659.       game.eatenEnemies = 0;
  660.    }
  661.    game.powerUp = 250;
  662.    var _loc2_ = 0;
  663.    while(_loc2_ < game.currentEnemies)
  664.    {
  665.       var _loc1_ = game["enemy" + _loc2_];
  666.       if(_loc1_.state == "normal" || _loc1_.state == "grace")
  667.       {
  668.          _loc1_.state = "afraid";
  669.          _loc1_.clip.gotoAndPlay("afraid");
  670.          switch(_loc1_.dir)
  671.          {
  672.             case 1:
  673.                _loc1_.dir = 3;
  674.                break;
  675.             case 2:
  676.                _loc1_.dir = 4;
  677.                break;
  678.             case 3:
  679.                _loc1_.dir = 1;
  680.                break;
  681.             case 4:
  682.                _loc1_.dir = 2;
  683.          }
  684.       }
  685.       _loc2_ = _loc2_ + 1;
  686.    }
  687. }
  688. function powerUpCount()
  689. {
  690.    if(game.powerUp == 0)
  691.    {
  692.       var _loc1_ = 0;
  693.       while(_loc1_ < game.currentEnemies)
  694.       {
  695.          var _loc2_ = "enemy" + _loc1_;
  696.          if(game[_loc2_].state == "afraid")
  697.          {
  698.             game[_loc2_].state = "normal";
  699.             game[_loc2_].clip.gotoAndPlay("normal");
  700.          }
  701.          _loc1_ = _loc1_ + 1;
  702.       }
  703.    }
  704.    else
  705.    {
  706.       loop2:
  707.       switch(game.powerUp)
  708.       {
  709.          case 10:
  710.          case 22:
  711.          case 34:
  712.          case 46:
  713.          case 58:
  714.          case 70:
  715.             _loc1_ = 0;
  716.             while(true)
  717.             {
  718.                if(_loc1_ >= game.currentEnemies)
  719.                {
  720.                   break loop2;
  721.                }
  722.                _loc2_ = "enemy" + _loc1_;
  723.                if(game[_loc2_].state == "afraid")
  724.                {
  725.                   game[_loc2_].clip.gotoAndPlay("blink");
  726.                }
  727.                _loc1_ = _loc1_ + 1;
  728.             }
  729.       }
  730.       game.powerUp--;
  731.    }
  732. }
  733. function onHeroDeath()
  734. {
  735.    if(--game.lives <= 0)
  736.    {
  737.       gotoAndStop("gameOver");
  738.       play();
  739.    }
  740.    else
  741.    {
  742.       buildMap(_root["map" + game.currentMap],false);
  743.       countdown.gotoAndPlay(1);
  744.    }
  745. }
  746. function onLevelUp()
  747. {
  748.    game.level = game.level + 1;
  749.    game.clip.bg.nextFrame();
  750.    game.clip.cage.gotoAndPlay("closed");
  751.    buildMap(_root["map" + game.currentMap],true);
  752.    countdown.gotoAndPlay(1);
  753. }
  754. game = {tileW:21,tileH:21,currentMap:1,totalPellets:0,goalDoor:null,interaction:false,level:1,lives:3,score:0,powerUp:0,eatenEnemies:0};
  755. score = 0;
  756. level = 0;
  757. livesDisplay.reset();
  758. unInstBtn._visible = false;
  759. pelletSound = new Sound();
  760. pelletSound.attachSound("pelletSound");
  761. pelletSound2 = new Sound();
  762. pelletSound2.attachSound("pelletSound2");
  763. ppSound = new Sound();
  764. ppSound.attachSound("ppSound");
  765. keySound = new Sound();
  766. keySound.attachSound("keySound");
  767. deadEnemySound = new Sound();
  768. deadEnemySound.attachSound("deadEnemySound");
  769. deathSound = new Sound();
  770. deathSound.attachSound("deathSound");
  771. var pelletBool = true;
  772. map1 = [[0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0],[0,2,3,2,0,4,5,6,0,0,0,2,0,0,0,4,5,6,0,2,3,2,0],[0,2,0,2,0,2,0,2,0,0,0,2,0,0,0,2,0,2,0,2,0,2,0],[0,2,0,2,2,2,0,2,0,0,0,2,0,0,0,2,0,2,2,2,0,2,0],[0,2,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,2,0],[0,2,2,2,2,2,2,2,2,2,4,5,6,2,2,2,2,2,2,2,0,2,0],[0,2,0,0,0,2,0,0,0,0,0,2,0,0,0,2,0,2,0,0,0,2,0],[0,2,0,0,0,2,2,2,0,2,2,2,2,2,2,2,0,2,2,2,0,2,0],[0,2,0,0,0,2,0,2,0,2,0,7,0,2,0,2,0,2,0,2,0,2,0],[0,2,2,2,2,2,0,2,2,2,0,1,0,2,0,2,2,2,0,2,2,2,0],[0,2,0,0,0,2,0,0,0,2,0,10,0,2,0,0,0,2,0,0,0,2,0],[0,2,2,2,2,2,0,2,2,2,0,0,0,2,0,2,2,2,0,2,2,2,0],[0,2,0,0,0,2,0,2,0,2,0,0,0,2,0,2,0,2,0,2,0,2,0],[0,2,0,0,0,2,2,2,0,2,2,2,2,2,2,2,0,2,2,2,0,2,0],[0,2,0,0,0,2,0,0,0,0,0,2,0,0,0,2,0,2,0,0,0,2,0],[0,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2,0,2,0],[0,2,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,2,0],[0,2,0,2,2,2,0,2,0,0,0,2,0,0,0,2,0,2,2,2,0,2,0],[0,2,0,2,0,2,0,2,0,0,0,2,0,0,0,2,0,2,0,2,0,2,0],[0,2,3,2,0,4,5,6,0,0,0,2,0,0,0,4,5,6,0,2,3,2,0],[0,0,0,0,0,0,0,0,0,0,0,9,0,0,0,0,0,0,0,0,0,0,0]];
  773. Tile0 = new TileClass(false,1,"wall");
  774. Tile1 = new TileClass(true,2,"blank");
  775. Tile2 = new TileClass(true,3,"pellet");
  776. Tile3 = new TileClass(true,4,"powerPellet");
  777. Tile4 = new TileClass(true,5,"keyLeft");
  778. Tile5 = new TileClass(true,6,"keyMiddle");
  779. Tile6 = new TileClass(true,7,"keyRight");
  780. Tile7 = new TileClass(false,8,"goalDoor");
  781. Tile8 = new DoorClass(11,19);
  782. Tile9 = new DoorClass(11,1);
  783. Tile10 = new TileClass(true,2,"goal");
  784. Tile11 = new TileClass(false,11,"openGoalDoor");
  785. _root.createEmptyMovieClip("controller",10);
  786. controller.onEnterFrame = function()
  787. {
  788.    if(game.interaction)
  789.    {
  790.       moveHero();
  791.       enemyBrain();
  792.       if(game.powerUp >= 0)
  793.       {
  794.          powerUpCount();
  795.       }
  796.    }
  797. };
  798. Enemy1 = new EnemyClass(1);
  799. Enemy2 = new EnemyClass(1);
  800. Enemy3 = new EnemyClass(1);
  801. enemyList = [[0],[[1,7,5],[2,15,5],[3,11,7]]];
  802. hero = {curDir:0,nextDir:0,xTile:11,yTile:15,speed:5.25};
  803. myKeyListener = {};
  804. Key.addListener(myKeyListener);
  805. myKeyListener.onKeyDown = function()
  806. {
  807.    if(game.interaction)
  808.    {
  809.       var _loc1_ = 0;
  810.       switch(Key.getCode())
  811.       {
  812.          case 38:
  813.             _loc1_ = 1;
  814.             break;
  815.          case 39:
  816.             _loc1_ = 2;
  817.             break;
  818.          case 40:
  819.             _loc1_ = 3;
  820.             break;
  821.          case 37:
  822.             _loc1_ = 4;
  823.             break;
  824.          case 32:
  825.             _loc1_ = 5;
  826.       }
  827.       if(_loc1_ != hero.curDir && _loc1_ != hero.nextDir)
  828.       {
  829.          if(hero.curDir == 0)
  830.          {
  831.             hero.curDir = _loc1_;
  832.             hero.nextDir = 0;
  833.          }
  834.          else
  835.          {
  836.             hero.nextDir = _loc1_;
  837.          }
  838.       }
  839.    }
  840. };
  841. buildMap(_root["map" + game.currentMap],true);
  842.